#include<stdio.h>
#include<stdlib.h>

#define MAXSIZE 100
typedef int ELemType;
typedef struct {
  ELemType *data;
  int front;
  int rear;
}Queue;

Queue* initQueue(){
  Queue *Q=(Queue*)malloc(sizeof(Queue));
  Q->data=(ELemType*)malloc(sizeof(ELemType)*MAXSIZE);
  Q->front=0;
  Q->rear=0;
  return Q;
}

int isEmpty(Queue *Q){
  if(Q->front==Q->rear){
    printf("队列为空\n");
    return 1;
  }
  return 0;
}

//出队
int dequeue(Queue *Q,ELemType *e){
  if(isEmpty(Q)==1){
    return 0;
  }
  *e=Q->data[Q->front];
  Q->front=(Q->front+1)%MAXSIZE;
  return 1;
}

//入队
int equeue(Queue *Q,ELemType e){
  if((Q->rear+1)%MAXSIZE==Q->front){
    printf("队列已满\n");
  }
  Q->data[Q->rear]=e;
  Q->rear=(Q->rear+1)%MAXSIZE;
  return 1;
}

//获取队头
ELemType getFront(Queue *Q){
  if(isEmpty(Q)==1) return 0;
  ELemType e=Q->data[Q->front];
  return e;
}

int main(){
  Queue *q = initQueue();
	equeue(q, 10);
	equeue(q, 20);
	equeue(q, 30);
	equeue(q, 40);
	equeue(q, 50);
	ELemType e;
	dequeue(q, &e);
	printf("出队%d\n", e);
	dequeue(q, &e);
	printf("出队%d\n", e);
	printf("%d\n", getFront(q));
	return 0;
}

